package com.cskaoyan.market.typeHandler;

/**
 * @ClassName Gender
 * @Description: TODO
 * @Author 远志 zhangsong@cskaoyan.onaliyun.com
 * @Date 2023/3/18 9:44
 * @Version V1.0
 **/
public enum Gender {

    MALE(0, "男性"),

    FEMALE(1, "女性");

    private Integer code;

    private String name;

    Gender(Integer code, String name) {
        this.code = code;
        this.name = name;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public static Integer getCodeByName(String name){
        Gender[] values = Gender.values();
        for (Gender value : values) {
            if(name.equals(value.getName())){
                return value.getCode();
            }
        }
        throw new IllegalArgumentException("参数有误");
    }


    public static String getNameByCode(Integer code){
        Gender[] values = Gender.values();
        for (Gender value : values) {
            if(code == value.getCode()){
                return value.getName();
            }
        }
        throw new IllegalArgumentException("参数有误");
    }
}
